﻿using NetCore8Demo.Models.Param;
using NetCore8Demo.Models.PLC;
using NetCore8Demo.Views.Param;
using NetCore8Demo.Views.PLC;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using NetCore8Demo.ViewModels.Communication.SerialPortFolder;
using NetCore8Demo.Views.Communication.SerialPortFolder;
using NetCore8Demo.Models.Communication.SerialPortFolder;
using NetCore8Demo.Tool;

namespace NetCore8Demo
{
    public partial class AdminTestForm : Form
    {
        public AdminTestForm()
        {
            InitializeComponent();
        }
        private void AdminTestForm_Load(object sender, EventArgs e)
        {

        }

        //查看PLC
        private void ShowPlcFormBtn_Click(object sender, EventArgs e)
        {
            List<string> strList = ["PLC信息", "扩展信息"];
            List<PlcAddressInfo> plcAddressInfoList = StaticPlc.LoadPlcAddressInfoList();
            ShowDynPlcAddressForm basicParamAddressForm = new ShowDynPlcAddressForm(plcAddressInfoList, strList);
            basicParamAddressForm.Show();
        }

        //编辑PLC
        private void EditPlcFormBtn_Click_1(object sender, EventArgs e)
        {
            EditPlcForm addressForm = new EditPlcForm();
            addressForm.ShowDialog();
        }

        //编辑PLC地址
        private void EditPlcAddressFormBtn_Click(object sender, EventArgs e)
        {
           // EditPlcAddressForm addressForm = new EditPlcAddressForm();
           // addressForm.ShowDialog();
        }

        //串口助手
        private void TestSerialPortBtn_Click(object sender, EventArgs e)
        {
            TestSerialPortForm form = new TestSerialPortForm();
            form.Show();
        }

        //串口编辑
        private void EditSerialPortBtn_Click(object sender, EventArgs e)
        {
            EditSerialPortForm form = new EditSerialPortForm();
            form.Show();
        }

        //参数编辑
        private void EditParamBtn_Click(object sender, EventArgs e)
        {
            List<ParamInfo> paramList = [];
            ParamInfo param = new ParamInfo
            {
                LabelName = "是否",
                OldValue = "True",
                ParamType = ParamType.YesOrNo,
            };

            paramList.Add(new ParamInfo("地址", "DBXXX"));
            ParamInfo param2 = new ParamInfo
            {
                LabelName = "数据类型",
                OldValue = PlcDataType.Short16 + "",
                ParamType = ParamType.ComboBox,
                ValueList = Enum.GetNames(typeof(PlcDataType)).ToList(),
            };
            paramList.Add(param);
            paramList.Add(param2);

            BasicParamForm basicParamForm = new BasicParamForm(paramList);
            basicParamForm.ShowDialog();

            if (!basicParamForm.SureFlag)
            {
                return;
            }
            string newParam1 = paramList[0].NewValue;
            string newParam2 = paramList[1].NewValue;
            string newParam3 = paramList[2].NewValue;

            MessageBox.Show(newParam1 + "," + newParam2 + "," + newParam3);


        }

     
    }
}
